home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / IFC_112 / netscape / application / TextAttachment.java < prev    next >
Encoding:
Text File  |  1999-05-28  |  4.7 KB  |  177 lines  |  [TEXT/CWIE]

  1. // TextAttachment.java
  2. // By Ned Etcode
  3. // Copyright 1995, 1996, 1997 Netscape Communications Corp.  All rights reserved.
  4.  
  5. package netscape.application;
  6.  
  7. import netscape.util.*;
  8.  
  9.  
  10. /** Abstract object subclass for placing items (Images, controls, and so on)
  11.   * among a TextView's characters. Use ImageAttachment to display an Image.
  12.   * Subclass TextAttachment for anything else.
  13.   * @see ImageAttachment
  14.   * @note 1.0 new API for becoming visible
  15.   * @note 1.1 removed invalid void return argument in constructor
  16.   */
  17. public abstract class TextAttachment implements Codable {
  18.     private TextView    _owner;
  19.     private int         _width, _height;
  20.     private boolean     _visible = false;
  21.  
  22.     final static String OWNER_KEY = "owner";
  23.     final static String WIDTH_KEY = "width";
  24.     final static String HEIGHT_KEY= "height";
  25.  
  26.     /** Constructs an empty TextAttachment.
  27.       */
  28.     public TextAttachment() {
  29.         _owner = null;
  30.         _width = _height = 0;
  31.     }
  32.  
  33.     /** Set <b>aTextView</b> as the TextAttachment's owner (the TextView that
  34.       * will display this TextAttachment).
  35.      */
  36.     public void setOwner(TextView aTextView) {
  37.         _owner = aTextView;
  38.     }
  39.  
  40.     /** Returns the TextAttachment's owner.
  41.       */
  42.     public TextView owner() {
  43.         return _owner;
  44.     }
  45.  
  46.     /** Sets the TextAttachment's pixel width.
  47.       */
  48.     public void setWidth(int width) {
  49.         _width = width;
  50.     }
  51.  
  52.     /** Returns the TextAttachment's pixel width.
  53.       * @see #setWidth
  54.       */
  55.     public int width() {
  56.         return _width;
  57.     }
  58.  
  59.     /** Sets the TextAttachment's pixel height.
  60.      */
  61.     public void setHeight(int height) {
  62.         _height = height;
  63.     }
  64.  
  65.     /** Returns the TextAttachment's pixel height.
  66.       * @see #setHeight
  67.       */
  68.     public int height() {
  69.         return _height;
  70.     }
  71.  
  72.     /** Method responsible for drawing the TextAttachment's contents
  73.       * within the Graphics <b>g</b>.  <b>boundsRect</b> is the
  74.       * TextAttachment's bounds within its owner's coordinate system.
  75.       */
  76.      public void drawInRect(Graphics g, Rect boundsRect) {
  77.      }
  78.  
  79.     /** Called by the TextAttachment's owner when the user clicks within
  80.       * the TextAttachment.  This method should return <b>false</b> if the
  81.       * TextAttachment isn't interested in the event, <b>true</b> otherwise.
  82.       */
  83.     public boolean mouseDown(MouseEvent event) {
  84.         return false;
  85.     }
  86.  
  87.     /** Called by the TextAttachment's owner as the user drags the mouse after
  88.       * having clicked within the TextAttachment.  Only called if
  89.       * <b>mouseDown()</b> returned <b>true</b>.
  90.       */
  91.     public void mouseDragged(MouseEvent event) {
  92.     }
  93.  
  94.     /** Called by the TextAttachment's owner when the user releases the mouse
  95.       * after having clicked within the TextAttachment.  Only called if
  96.       * <b>mouseDown()</b> returned <b>true</b>.
  97.       */
  98.     public void mouseUp(MouseEvent event) {
  99.     }
  100.  
  101.  
  102.     /** Called when the attachment is about to get visible for the first
  103.       * time.
  104.       *
  105.       */
  106.     public void willBecomeVisibleWithBounds(Rect bounds) {
  107.     }
  108.  
  109.     /** Called when the attachment bounds did change.
  110.       *
  111.       */
  112.     public void boundsDidChange(Rect newBounds) {
  113.     }
  114.  
  115.     /** Called when the attachment is about to get removed
  116.       *
  117.       */
  118.     public void willBecomeInvisible() {
  119.     }
  120.  
  121.     /** Describes the TextAttachment class's information.
  122.       * @see Codable#describeClassInfo
  123.       */
  124.     public void describeClassInfo(ClassInfo info) {
  125.         info.addClass("netscape.application.TextAttachment", 1);
  126.         info.addField(OWNER_KEY,OBJECT_TYPE);
  127.         info.addField(WIDTH_KEY,INT_TYPE);
  128.         info.addField(HEIGHT_KEY,INT_TYPE);
  129.     }
  130.  
  131.     /** Encodes the TextAttachment instance.
  132.       * @see Codable#encode
  133.       */
  134.     public void encode(Encoder encoder) throws CodingException {
  135.         encoder.encodeObject(OWNER_KEY,_owner);
  136.         encoder.encodeInt(WIDTH_KEY,_width);
  137.         encoder.encodeInt(HEIGHT_KEY,_height);
  138.     }
  139.  
  140.     /** Decodes the TextAttachment instance.
  141.       * @see Codable#decode
  142.       */
  143.     public void decode(Decoder decoder) throws CodingException {
  144.         _owner = (TextView)decoder.decodeObject(OWNER_KEY);
  145.         _width = decoder.decodeInt(WIDTH_KEY);
  146.         _height= decoder.decodeInt(HEIGHT_KEY);
  147.     }
  148.  
  149.     /** Finishes the TextAttachment decoding.
  150.       * @see Codable#finishDecoding
  151.       */
  152.     public void finishDecoding() throws CodingException {
  153.     }
  154.  
  155.     void _willShowWithBounds(Rect rect) {
  156.         if( _visible )
  157.             boundsDidChange(rect);
  158.         else {
  159.             willBecomeVisibleWithBounds(rect);
  160.             _visible = true;
  161.         }
  162.     }
  163.  
  164.     void _willHide() {
  165.         willBecomeInvisible();
  166.         _visible = false;
  167.     }
  168. }
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.